package com.mingtu.guards.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.guards.R;
import com.mingtu.guards.bean.FileTypeBean;

public class FileParentAdapter extends BaseQuickAdapter<FileTypeBean.ListBean, BaseViewHolder> {
    public FileParentAdapter() {
        super(R.layout.item_file_data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, FileTypeBean.ListBean listBean) {
        String name = listBean.getName();
        helper.setText(R.id.tv_file_name, name);
        boolean isCheck = listBean.isCheck();
        ImageView ivCheck = helper.getView(R.id.iv_check);
        if (isCheck) {
            ivCheck.setVisibility(View.VISIBLE);
        } else {
            ivCheck.setVisibility(View.GONE);
        }
    }

    /**
     * 修改状态
     *
     * @param position
     */
    public void updateStatus(int position) {
        if (mData != null && mData.size() > 0) {
            FileTypeBean.ListBean listBean = mData.get(position);
            listBean.setCheck(true);
            mData.set(position, listBean);
            notifyItemChanged(position);
        }

    }

    /**
     * 重置状态
     */
    public void resetStatus(int position) {
        if (mData != null && mData.size() > 0) {
            FileTypeBean.ListBean listBean = mData.get(position);
            listBean.setCheck(false);
            mData.set(position, listBean);
            notifyItemChanged(position);
        }
    }

}
